<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>区块链交易平台-用户注册</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <link rel="stylesheet" href="${request.contextPath}/statics/css/bootstrap.min.css">
    <link rel="stylesheet" href="${request.contextPath}/statics/css/font-awesome.min.css">
    <link rel="stylesheet" href="${request.contextPath}/statics/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="${request.contextPath}/statics/css/all-skins.min.css">
    <link rel="stylesheet" href="${request.contextPath}/statics/css/main.css">
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body class="hold-transition register-page">
<div class="register-box" id="rrapp">
    <div class="register-logo">
        <b>区块链交易平台-用户注册</b>
    </div>

    <div class="register-box-body">
        <p class="login-box-msg">注册新用户</p>
        <div v-if="error" class="alert alert-danger alert-dismissible">
            <h4 style="margin-bottom: 0px;"><i class="fa fa-exclamation-circle"></i> {{errorMsg}}</h4>
        </div>
        <!--<form action="sys/" method="post">-->
        <div class="form-group has-feedback">
            <input type="text" class="form-control" v-model="username" placeholder="昵称">
            <span class="glyphicon glyphicon-user form-control-feedback"></span>
        </div>
        <div class="form-group has-feedback">
            <input type="email" class="form-control" v-model="email" placeholder="邮箱地址">
            <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
        </div>
        <div class="form-group has-feedback">
            <input type="phone" class="form-control" v-model="mobile" placeholder="手机号">
            <span class="glyphicon glyphicon-phone form-control-feedback"></span>
        </div>
        <div class="form-group has-feedback">
            <input type="password" class="form-control" v-model="password" placeholder="密码">
            <span class="glyphicon glyphicon-lock form-control-feedback"></span>
        </div>
        <div class="form-group has-feedback">
            <input type="password" class="form-control" v-model="confirmpwd" placeholder="确认密码">
            <span class="glyphicon glyphicon-log-in form-control-feedback"></span>
        </div>
        <div class="row">
            <div class="col-xs-8">
                <div class="checkbox icheck">
                    <label>
                        <input type="checkbox"> 阅读并同意 <a href="#">用户协议</a>
                    </label>
                </div>
            </div>
            <!-- /.col -->
            <div class="col-xs-4">
                <button type="submit" class="btn btn-primary btn-block btn-flat" @click="register">注册</button>
            </div>
            <!-- /.col -->
        </div>
        <!--</form>-->
        <a href="login.html" class="text-center">已经是会员</a>
    </div>
    <!-- /.form-box -->
</div>
<!-- /.register-box -->

<script src="${request.contextPath}/statics/libs/jquery.min.js"></script>
<script src="${request.contextPath}/statics/libs/vue.min.js"></script>
<script src="${request.contextPath}/statics/libs/bootstrap.min.js"></script>
<script src="${request.contextPath}/statics/libs/jquery.slimscroll.min.js"></script>
<script src="${request.contextPath}/statics/libs/fastclick.min.js"></script>
<script src="${request.contextPath}/statics/libs/app.js"></script>
<script type="text/javascript">
    var baseURL = "${request.contextPath}/";
    $(function () {
        $('input').iCheck({
            checkboxClass: 'icheckbox_square-blue',
            radioClass: 'iradio_square-blue',
            increaseArea: '20%' // optional
        });
    });
    var vm = new Vue({
        el: '#rrapp',
        data: {
            username: '',
            password: '',
            confirmpwd: null,
            email: '',
            mobile: '',
            error: false,
            errorMsg: ''
        },
        beforeCreate: function () {
            if (self != top) {
                top.location.href = self.location.href;
            }
        },
        methods: {
            register: function () {
                if (vm.password == vm.confirmpwd) {
                    $.ajax({
                        type: "POST",
                        url: baseURL + "/sys/user/register",
                        data: {
                            username: vm.username,
                            password: vm.password,
                            email: vm.email,
                            mobile: vm.mobile
                        },
                        dataType: "json",
                        success: function (r) {
                            console.log({r: r})
                            if (r.code == 0) {
                                parent.location.href = 'login.html';
                            } else {
                                vm.error = true;
                                vm.errorMsg = r.msg
                            }
                        }
                    });
                } else {
                    vm.error = true;
                    vm.errorMsg = '两次输入密码不一致!'
                }
            }
        }
    });
</script>
</body>
</html>
